<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;




use app\admin\model\CaiwuModel;

class Caiwu extends Base
{
    //用户列表
    public function index()
    {
        
        if(request()->isAjax()){

            $param = input('param.');

            $limit = $param['pageSize'];
            $offset = ($param['pageNumber'] - 1) * $limit;

            $where = [];
            if (!empty($param['searchText']['username'])) {
                $where['b.user_name|b.phone'] = ['like', '%' . $param['searchText']['username'] . '%'];
            }
            if (!empty($param['searchText']['type'])){
                $where['a.type'] = $param['searchText']['type'];
            }
            if (!empty($param['searchText']['addtime'])) {
                $time = explode('-',$param['searchText']['addtime']);

                $startTime = strtotime($time[0].'-'.$time[1].'-'.$time[2]);
                $endTime = strtotime($time[3].'-'.$time[4].'-'.$time[5]);

                $where['a.addtime'] = array(array('gt',$startTime),array('lt',$endTime));
            }

            $user = new CaiwuModel();
            $selectResult = $user->getCaiwuByWhere($where, $offset, $limit);


            $return['total'] = $user->getAllCaiwu($where);  //总数据
            $return['rows'] = $selectResult;

            return json($return);
        }

        return $this->fetch();
    }


}
